package net.oschina.arvin.dbjava.table;

import net.oschina.arvin.dbjava.util.Utils;

/**
 * 不管下划线还是什么，都统一转成驼峰
 *
 * @author Arvin
 * @time 2017/9/29 14:50
 */
public class DefaultColumnNameToFieldConverter implements ColumnNameToFieldConverter {

    public static final DefaultColumnNameToFieldConverter INSTANCE = new DefaultColumnNameToFieldConverter();

    @Override
    public String convert(String columnName) {
        // 按下划线分割每一个单词
        String[] words = columnName.split("_");
        StringBuilder builder = new StringBuilder();
        for (String word : words) {
            if (Utils.isNotBlank(word)) {
                builder.append(Utils.firstLetterUpperCase(word));
            }
        }
        return Utils.firstLetterLowerCase(builder.toString());
    }
}
